package it.polimi.digitalstate.entities;

import it.polimi.digitalstate.dto.PartyDTO;

import java.io.Serializable;
import java.lang.String;
import java.sql.Date;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * Entity implementation class for Entity: Party
 *
 */
@Entity
@NamedQueries(value = { 
		@NamedQuery(name = "getallparties", query = "select p from Party p order by p.name " ),
		@NamedQuery(name = "party_getByName", query = "select p from Party p where p.name=:name" ),
		@NamedQuery(name = "party_getByID", query = "select p from Party p where p.id=:id " ),
		@NamedQuery(name = "party_getBySymbol", query = "select p from Party p where p.symbol=:symbol" )
		})
public class Party implements Serializable , IEntity{
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;   
	@Column(nullable=false, unique=true)
	private String name;
	//TODO For the moment symbol is represented with a string (the path), but i don't know what's the best way to represent it.
	@Column(nullable = false, unique=true)
	@NotNull
	private String symbol;
	@NotNull
	@Lob 
	@Column(nullable=false, name="program", length=512)
	private String program;
	@Column(nullable = false)
	private Date creation_date;
	private Date ending_date;
	private static final long serialVersionUID = 1L;

	public Party() {
		super();
	}   
	public Party(PartyDTO party_dto){
		super();
		name=party_dto.getName();
		symbol=party_dto.getSymbol();
		program = party_dto.getProgram();
		//it should retrieve the date of today
		creation_date = new Date(new java.util.Date().getTime());
	}
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}   
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}   
	public String getSymbol() {
		return this.symbol;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}   
	public String getProgram() {
		return this.program;
	}

	public void setProgram(String program) {
		this.program = program;
	}   
	public Date getCreation_date() {
		return this.creation_date;
	}

	public void setCreation_date(Date creation_date) {
		this.creation_date = creation_date;
	}   
	public Date getEnding_date() {
		return this.ending_date;
	}

	public void setEnding_date(Date ending_date) {
		this.ending_date = ending_date;
	}
	
	public PartyDTO getDTO(){
		return new PartyDTO(id,name, symbol, program);
	}
   
}
